define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'inquiryform/index' + location.search,
                    add_url: 'inquiryform/add',
                    edit_url: 'inquiryform/edit',
                    del_url: 'inquiryform/del',
                    multi_url: 'inquiryform/multi',
                    import_url: 'inquiryform/import',
                    table: 'inquiry_form',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'group_id', title: __('Group_id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.username', title: __('群主昵称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.tel', title: __('群主手机号'), operate: 'LIKE'},
                        {field: 'group.name', title: __('Group.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_bid', title: __('Is_bid'), searchList: {"1":__('Is_bid 1'),"2":__('Is_bid 2')}, formatter: Table.api.formatter.normal},
                        {field: 'userbid.username', title: __('成交人昵称')},
                        {field: 'userbid.tel', title: __('成交人手机号')},
                        {field: 'bid_price', title: __('Bid_price'), operate:'BETWEEN'},
                        {field: 'add_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        // {field: 'group.type', title: __('Group.type')},
                        
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                        buttons: [
                            {
                                name: 'edit',
                                text: __('查看报价'),
                                title: __('查看报价'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend: 'data-area=\'["70%", "60%"]\'',
                                url: 'inquiryprice/index',
                            },
                            {
                                name: 'edit',
                                text: __('查看'),
                                title: __('查看'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend: 'data-area=\'["70%", "60%"]\'',
                                url: 'inquiryform/edit',
                            }
                            
                        ], 
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
